Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jonas 49 posts 21 karma points
    Apr 29, 2009 @ 14:18
    Jonas
    0

    Iterate media nodes with Api [solved]

    Hi, I've been trying to figure out how to iterate through all the media nodes with the Api and get the names, parent id's, node id's and media type of each media node. But I apparently have to less knowledge about XmlNavigation. Can someone give me a hint? Thanx! (Can I use NodeFactory for media nodes?)

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Apr 29, 2009 @ 14:53
    Dirk De Grave
    0

    Hi,

    I think GetMedia(int mediaId, bool deep) could do that. (Found in library class, and also available as xslt extension function)

    Hope this helps.

    Regards,
    /Dirk



  • Jonas 49 posts 21 karma points
    Apr 29, 2009 @ 17:43
    Jonas
    0

    Yes, thanks, but that gives me an XPathNodeIterator, how to use that? :-k

    nodes=umbraco.library.GetMedia(id, True);
    While (nodes.MoveNext())
    nodes.Current.Value

    I'm stuck ](*,)

    I've tried XPathNodeIterator.Current.GetAttribute(localName As String, namespaceURI As
    String) with no luck

  • Jonas 49 posts 21 karma points
    Apr 29, 2009 @ 21:23
    Jonas
    0

    Yikes, this was hard. I struggled to get this working but kinda ugly solution:

    [code] protected void Button1_Click(object sender, EventArgs e)
    {
    IterateMediaNodes(Convert.ToInt32(TextBox1.Text));
    }
    void IterateMediaNodes(int rootNodeId)
    {
    System.Xml.XPath.XPathNodeIterator it= umbraco.library.GetMedia(rootNodeId, true);
    XmlNodesEnumerable xem = new XmlNodesEnumerable(it);

    foreach (XmlNode node in xem)
    {
    try
    {
    Response.Write("NAME:" + node.Attributes.GetNamedItem("nodeName").Value + "
    ");
    Response.Write("TYPE:" + node.Attributes.GetNamedItem("nodeTypeAlias").Value + "
    ");
    Response.Write("PATH:" + node.Attributes.GetNamedItem("path").Value + "
    ");
    Response.Write("umbracoFile:" + node.SelectSingleNode("./data[@alias='umbracoFile']").InnerText + "
    ");
    Response.Write("umbracoExtension:" + node.SelectSingleNode("./data[@alias='umbracoExtension']").InnerText + "
    ");
    }
    catch (Exception)
    {

    }

    if (node.HasChildNodes)
    recurseNodes(node.ChildNodes);
    }

    }
    protected void recurseNodes(XmlNodeList nodes)
    {
    foreach (XmlNode node in nodes)
    {
    try
    {
    Response.Write("NAME:" + node.Attributes.GetNamedItem("nodeName").Value + "
    ");
    Response.Write("TYPE:" + node.Attributes.GetNamedItem("nodeTypeAlias").Value + "
    ");
    Response.Write("PATH:" + node.Attributes.GetNamedItem("path").Value + "
    ");
    Response.Write("umbracoFile:" + node.SelectSingleNode("./data[@alias='umbracoFile']").InnerText + "
    ");
    Response.Write("umbracoExtension:" + node.SelectSingleNode("./data[@alias='umbracoExtension']").InnerText + "
    ");
    }
    catch (Exception)
    {

    }
    if (node.HasChildNodes)
    recurseNodes(node.ChildNodes);
    }

    }[/code]

    I'm using the class XmlNodesEnumerable found here http://weblogs.asp.net/cazzu/archive/2004/03/09/86609.aspx

  • Jonas 49 posts 21 karma points
    Apr 30, 2009 @ 00:53
    Jonas
    1

    -o - the best solution is ofcourse getting the media node like this:


    using umbraco.cms.businesslogic.media;

    [code]Media m = new Media(nodeId);

    foreach (Media mChild in m.Children)

    ...

    if (mChild.ContentType.Alias=="Folder")

    ...

    [/code]

  • Jonas 49 posts 21 karma points
    Apr 30, 2009 @ 08:43
    Jonas
    0

    Finally, after tooo many hours I got it working, phew.

    Whats working? It's a simple mirror function that replicates files from a folder on a remote host to the Umbraco media archive (with folder hierarchy). The user just selects a start node in Media and a physical path on the remote server.

    The routine leaves existing files, it does not (yet) check for newer versions and does not delete files that has been deleted on the remote host. Also it's supposed to be scheduled... But for now it's working good enough so that I can go on with other things on the project. :)

    Ref http://articles.techrepublic.com.com/5100-10878_11-5805105.html (webservice file up/download).

Please Sign in or register to post replies

Write your reply to:

Draft